home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Expanders / BOOPSI / funcs.c next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  10.9 KB  |  423 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <string.h>                     // ANSI
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8.  
  9. #include <exec/nodes.h>                 // exec
  10. #include <exec/lists.h>
  11. #include <exec/memory.h>
  12. #include <exec/types.h>
  13. #include <dos/dos.h>                    // dos
  14. #include <dos/dostags.h>
  15. #include <intuition/intuition.h>        // intuition
  16. #include <intuition/gadgetclass.h>
  17. #include <graphics/text.h>              // graphics
  18. #include <gadgets/colorwheel.h>         // gadgets
  19. #include <libraries/gadtools.h>         // libraries
  20. #include <libraries/reqtools.h>
  21. #include <clib/exec_protos.h>           // protos
  22. #include <clib/dos_protos.h>
  23. #include <clib/intuition_protos.h>
  24. #include <clib/reqtools_protos.h>
  25. #include <pragmas/exec_pragmas.h>       // pragmas
  26. #include <pragmas/dos_pragmas.h>
  27. #include <pragmas/intuition_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/gadtools_pragmas.h>
  30. #include <pragmas/reqtools_pragmas.h>
  31.  
  32. #define BOOPSI_IEX
  33.  
  34. #include "DEV_IE:Expanders/defs.h"
  35. ///
  36. /// Prototypes
  37. static void     FGetString( BPTR, STRPTR );
  38. static void     PutString( BPTR, STRPTR );
  39. ///
  40. /// Data
  41. struct BOOPSITag Tags[]= {
  42.     NULL, NULL, TT_LONG, 0, "WHEEL_Hue", WHEEL_Hue, { NULL, NULL, NULL },
  43.     NULL, NULL, TT_LONG, 0, "WHEEL_Saturation", WHEEL_Saturation, { NULL, NULL, NULL },
  44.     NULL, NULL, TT_LONG, 0, "WHEEL_Brightness", WHEEL_Brightness, { NULL, NULL, NULL },
  45.     NULL, NULL, TT_USER_STRUCT, 0, "WHEEL_HSB", WHEEL_HSB, { NULL, NULL, NULL },
  46.     NULL, NULL, TT_LONG, 0, "WHEEL_Red", WHEEL_Red, { NULL, NULL, NULL },
  47.     NULL, NULL, TT_LONG, 0, "WHEEL_Green", WHEEL_Green, { NULL, NULL, NULL },
  48.     NULL, NULL, TT_LONG, 0, "WHEEL_Blue", WHEEL_Blue, { NULL, NULL, NULL },
  49.     NULL, NULL, TT_USER_STRUCT, 0, "WHEEL_RGB", WHEEL_RGB, { NULL, NULL, NULL },
  50.     NULL, NULL, TT_SCREEN, 0, "WHEEL_Screen", WHEEL_Screen, { NULL, NULL, NULL },
  51.     NULL, NULL, TT_STRING, 0, "WHEEL_Abbrv", WHEEL_Abbrv, { NULL, NULL, NULL },
  52.     NULL, NULL, TT_WORD_PTR, 0, "WHEEL_Donation", WHEEL_Donation, { NULL, NULL, NULL },
  53.     NULL, NULL, TT_BOOL, 0, "WHEEL_BevelBox", WHEEL_BevelBox, { NULL, NULL, NULL },
  54.     NULL, NULL, TT_LONG, 0, "WHEEL_MaxPens", WHEEL_MaxPens, { NULL, NULL, NULL },
  55.     NULL, NULL, TT_OBJECT, 0, "WHEEL_GradientSlider", WHEEL_GradientSlider, { NULL, NULL, NULL },
  56.     NULL, NULL, TT_WORD, 0, "GA_ID", GA_ID, { NULL, NULL, NULL },
  57. };
  58.  
  59. #define NUM_TAGS    ( sizeof( Tags ) / sizeof( struct BOOPSITag ))
  60. ///
  61.  
  62.  
  63.  
  64. /// I/O support functions
  65. void FGetString( BPTR File, STRPTR str )
  66. {
  67.     UBYTE   len;
  68.  
  69.     len = FGetC( File );
  70.  
  71.     FRead( File, str, len, 1 );
  72.  
  73.     str[ len ] = '\0';
  74.  
  75.     if(!( len & 1 ))
  76.     FGetC( File );
  77. }
  78.  
  79. void PutString( BPTR File, STRPTR str )
  80. {
  81.     UBYTE   len;
  82.  
  83.     len = strlen( str );
  84.  
  85.     FPutC( File, len );
  86.     FWrite( File, str, len, 1 );
  87.  
  88.     if(!( len & 1 ))
  89.     FPutC( File, 0 );
  90. }
  91. ///
  92.  
  93.  
  94. /*  Starting function           */
  95. /// IEX_Mount
  96. __geta4 ULONG IEX_Mount( __A0 struct IE_Data *IE )
  97. {
  98.     BPTR                    DescFile;
  99.     struct FileInfoBlock   *fib;
  100.     ULONG                   ret = IEX_ERROR_NO_DESC_FILE;
  101.     static UBYTE            FileName[] = "PROGDIR:Expanders/BOOPSI.desc";
  102.     ULONG                   c;
  103.  
  104.     Forbid();   /* we're going to write to a GLOBAL variable */
  105.  
  106.     if( Desc ) {            /* already mounted? */
  107.     Permit();
  108.     return( IEX_OK );
  109.     }
  110.  
  111.     LibBase->IEX.Kind       = IEX_BOOPSI_KIND;
  112.  
  113.     LibBase->IEX.Resizable  = TRUE;
  114.     LibBase->IEX.Movable    = TRUE;
  115.     LibBase->IEX.HasItems   = FALSE;
  116.     LibBase->IEX.UseFonts   = FALSE;
  117.  
  118.     LibBase->IEX.Node.ln_Name = "Color Wheel";
  119.  
  120.     LibBase->BOOPSIType     = BT_GADGET;
  121.  
  122.     NewList(( struct List * )&LibBase->Tags );
  123.  
  124.     for( c = 0; c < NUM_TAGS; c++ )
  125.     AddTail(( struct List * )&LibBase->Tags, ( struct Node * )&Tags[ c ]);
  126.  
  127.     if( fib = AllocDosObject( DOS_FIB, NULL )) {
  128.     if( DescFile = Lock( FileName, ACCESS_READ )) {
  129.  
  130.         Examine( DescFile, fib );
  131.         UnLock( DescFile );
  132.  
  133.         if( Desc = AllocVec( fib->fib_Size, 0L )) {
  134.         if( DescFile = Open( FileName, MODE_OLDFILE )) {
  135.  
  136.             Read( DescFile, Desc, fib->fib_Size );
  137.             Close( DescFile );
  138.  
  139.             ( *IE->IEXFun->SplitLines )( Desc ); // VERY important!
  140.  
  141.             STRPTR pri;
  142.  
  143.             pri = ( *IE->IEXFun->GetFirstLine )( Desc, "RENDPRI" );
  144.  
  145.             if( pri )
  146.             LibBase->IEX.Node.ln_Pri = atoi( pri );
  147.             else
  148.             LibBase->IEX.Node.ln_Pri = 0;
  149.  
  150.             ret = IEX_OK;
  151.  
  152.         } else {
  153.             FreeVec( Desc );
  154.             Desc = NULL;
  155.         }
  156.         }
  157.  
  158.     }
  159.  
  160.     FreeDosObject( DOS_FIB, fib );
  161.     }
  162.  
  163.     Permit();
  164.  
  165.     return( ret );
  166. }
  167. ///
  168.  
  169.  
  170. /*  Edit functions              */
  171. /// IEX_Add
  172. __geta4 BOOL IEX_Add( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 WORD x, __D2 WORD y, __D3 UWORD width, __D4 UWORD height )
  173. {
  174.     struct BOOPSIInfo   *Obj;
  175.     BOOL                ret = FALSE;
  176.  
  177.     if( Obj = (*IE->Functions->AllocObject)( IE_BOOPSI )) {
  178.  
  179.     Obj->Kind   = ID;       /* DON'T FORGET!!! */
  180.     Obj->Left   = x;
  181.     Obj->Top    = y;
  182.     Obj->Width  = width;
  183.     Obj->Height = height;
  184.     Obj->Flags  = G_ATTIVO; /* make it active  */
  185.  
  186.     sprintf( Obj->Label, "%sGad%03ld",
  187.          IE->win_info->wi_Label,
  188.          IE->win_info->wi_NewGadID );
  189.     IE->win_info->wi_NewGadID += 1;
  190.  
  191.     /* add our object to the list */
  192.     AddTail((struct List *)&IE->win_info->wi_Gadgets, (struct Node *)Obj );
  193.  
  194.     IE->win_info->wi_NumObjects += 1;
  195.  
  196.     ret = TRUE;
  197.     }
  198.  
  199.     return( ret );
  200. }
  201. ///
  202. /// IEX_Remove
  203. __geta4 void IEX_Remove( __D0 UWORD ID, __A0 struct IE_Data *IE )
  204. {
  205.     struct BOOPSIInfo   *Obj, *next;
  206.  
  207.     for( Obj = IE->win_info->wi_Gadgets.mlh_Head; Obj->Node.ln_Succ; Obj = Obj->Node.ln_Succ ) {
  208.     /* remove only the objects of our kind and that are selected  */
  209.     if(( Obj->Kind == ID ) && ( Obj->Flags & G_ATTIVO )) {
  210.         next = Obj->Node.ln_Pred;
  211.  
  212.         Remove(( struct Node * )Obj );
  213.  
  214.         IE->win_info->wi_NumObjects -= 1;
  215.  
  216.         (*IE->Functions->FreeObject)( Obj, IE_BOOPSI );
  217.         Obj = next;
  218.     }
  219.     }
  220. }
  221. ///
  222. /// IEX_Edit
  223. __geta4 BOOL IEX_Edit( __D0 UWORD ID, __A0 struct IE_Data *IE )
  224. {
  225.     /*      This function is not used by BOOPSI expanders       */
  226.     return( TRUE );
  227. }
  228. ///
  229. /// IEX_Copy
  230. __geta4 BOOL IEX_Copy( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 WORD offx, __D2 WORD offy )
  231. {
  232.     struct BOOPSIInfo   *Obj, *copy;
  233.  
  234.     for( Obj = IE->win_info->wi_Gadgets.mlh_Head; Obj->Node.ln_Succ; Obj = Obj->Node.ln_Succ ) {
  235.     if(( Obj->Kind == ID ) && ( Obj->Flags & G_ATTIVO )) {
  236.  
  237.         if( copy = (*IE->Functions->AllocObject)( IE_BOOPSI )) {
  238.  
  239.         CopyMem((char *)Obj, (char *)copy, (long)sizeof( struct BOOPSIInfo ));
  240.  
  241.         AddTail((struct List *)&IE->win_info->wi_Gadgets, (struct Node *)copy );
  242.  
  243.         IE->win_info->wi_NumObjects += 1; /* Don't forget! */
  244.  
  245.         copy->Left += offx;  /* update its position */
  246.         copy->Top  += offy;
  247.  
  248.         /* I don't want a neverending loop... ;-) */
  249.         copy->Flags &= ~G_ATTIVO;
  250.  
  251.         } else
  252.         return( FALSE );
  253.     }
  254.     }
  255.  
  256.     return( TRUE );
  257. }
  258. ///
  259. /// IEX_Make
  260. __geta4 struct Gadget *IEX_Make( __D0 UWORD ID, __A0 struct IE_Data *IE, __A1 struct Gadget *glist )
  261. {
  262.     /*  We don't need to make anything  */
  263.     return( glist );
  264. }
  265. ///
  266. /// IEX_Free
  267. __geta4 void IEX_Free( __D0 UWORD ID, __A0 struct IE_Data *IE )
  268. {
  269.     /*  We've got nothing to free when the window is closed  */
  270. }
  271. ///
  272. /// IEX_Refresh
  273. __geta4 void IEX_Refresh( __D0 UWORD ID, __A0 struct IE_Data *IE )
  274. {
  275. }
  276. ///
  277.  
  278.  
  279. /*  I/O Functions               */
  280. /// IEX_Save
  281. __geta4 void IEX_Save( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 BPTR File )
  282. {
  283. }
  284. ///
  285. /// IEX_Load
  286. __geta4 BOOL IEX_Load( __D0 UWORD ID, __A0 struct IE_Data *IE, __D1 BPTR File, __D2 UWORD Num )
  287. {
  288. }
  289. ///
  290.  
  291.  
  292. /*  Source related functions    */
  293. /// IEX_StartSrcGen
  294. __geta4 STRPTR IEX_StartSrcGen( __D0 UWORD ID, __A0 struct IE_Data *IE )
  295. {
  296.     struct WindowInfo  *wnd;
  297.     struct BOOPSIInfo   *Obj;
  298.     STRPTR              func;
  299.  
  300.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  301.     if( wnd->wi_NumObjects ) {
  302.         for( Obj = wnd->wi_Gadgets.mlh_Head; Obj->Node.ln_Succ; Obj = Obj->Node.ln_Succ ) {
  303.         if( Obj->Kind == ID )
  304.             wnd->wi_NeedRender = TRUE;
  305.         }
  306.     }
  307.     }
  308.  
  309.     func = ( IE->SrcFlags & FONTSENSITIVE ) ? "SUPPORT-FA" : "SUPPORT";
  310.  
  311.     return(( *IE->IEXFun->GetFirstLine )( Desc, func ));
  312. }
  313. ///
  314. /// IEX_WriteGlobals
  315. __geta4 void IEX_WriteGlobals( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  316. {
  317. }
  318. ///
  319. /// IEX_WriteSetup
  320. __geta4 void IEX_WriteSetup( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  321. {
  322. }
  323. ///
  324. /// IEX_WriteCloseDown
  325. __geta4 void IEX_WriteCloseDown( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  326. {
  327. }
  328. ///
  329. /// IEX_WriteHeaders
  330. __geta4 void IEX_WriteHeaders( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  331. {
  332.     STRPTR string;
  333.  
  334.     if( string = ( *IE->IEXFun->GetFirstLine )( Desc, "HEADER" ))
  335.     FPuts( Files->XDef, string );
  336. }
  337. ///
  338. /// IEX_WriteRender
  339. __geta4 void IEX_WriteRender( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  340. {
  341.     struct Descriptor   Dsc[] = {
  342.     { 'w', IE->win_info->wi_Label },
  343.     { 'o', NULL },
  344.     { 0, NULL }
  345.     };
  346.     struct BOOPSIInfo   *Obj;
  347.     STRPTR              String;
  348.  
  349.     if(( IE->win_info->wi_NumObjects ) && ( String = ( *IE->IEXFun->GetFirstLine )( Desc, "RENDER" ))) {
  350.     for( Obj = IE->win_info->wi_Gadgets.mlh_Head; Obj->Node.ln_Succ; Obj = Obj->Node.ln_Succ ) {
  351.         if( Obj->Kind == ID ) {
  352.         Dsc[1].Meaning = Obj->Label;
  353.         ( *IE->IEXFun->WriteFormatted )( Files->Std, String, &Dsc[0] );
  354.         }
  355.     }
  356.     }
  357. }
  358. ///
  359. /// IEX_GetIDCMP
  360. __geta4 ULONG IEX_GetIDCMP( __D0 UWORD ID, __D1 ULONG idcmp, __A0 struct IE_Data *IE )
  361. {
  362.     return( idcmp );
  363. }
  364. ///
  365. /// IEX_WriteData
  366. __geta4 void IEX_WriteData( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  367. {
  368.     UBYTE               X[6], Y[6], Width[6], Height[6];
  369.     struct Descriptor   Dsc[] = {
  370.     { 'o', NULL },
  371.     { 'x', X },
  372.     { 'y', Y },
  373.     { 'W', Width },
  374.     { 'h', Height },
  375.     { 0, NULL }
  376.     };
  377.     struct BOOPSIInfo   *Obj;
  378.     struct WindowInfo  *wnd;
  379.     STRPTR              Xdef, Data;
  380.     static UBYTE        ld[] = "%ld";
  381.  
  382.     Xdef = ( *IE->IEXFun->GetFirstLine )( Desc, "EXTERN" );
  383.     Data = ( *IE->IEXFun->GetFirstLine )( Desc, "DATA" );
  384.  
  385.     for( wnd = IE->win_list.mlh_Head; wnd->wi_succ; wnd = wnd->wi_succ ) {
  386.     if( wnd->wi_NumObjects ) {
  387.         for( Obj = wnd->wi_Gadgets.mlh_Head; Obj->Node.ln_Succ; Obj = Obj->Node.ln_Succ ) {
  388.         if( Obj->Kind == ID ) {
  389.  
  390.             Dsc[0].Meaning = Obj->Label;
  391.  
  392.             if( Xdef )
  393.             ( *IE->IEXFun->WriteFormatted )( Files->XDef, Xdef, &Dsc[0] );
  394.  
  395.             sprintf( X, ld, Obj->Left - IE->ScreenData->XOffset );
  396.             sprintf( Y, ld, Obj->Top  - IE->ScreenData->YOffset );
  397.             sprintf( Width, ld, Obj->Width );
  398.             sprintf( Height, ld, Obj->Height );
  399.  
  400.             if( Data )
  401.             ( *IE->IEXFun->WriteFormatted )( Files->Std, Data, &Dsc[0] );
  402.         }
  403.         }
  404.     }
  405.     }
  406. }
  407. ///
  408. /// IEX_WriteChipData
  409. __geta4 void IEX_WriteChipData( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  410. {
  411. }
  412. ///
  413. /// IEX_WriteOpenWnd
  414. __geta4 void IEX_WriteOpenWnd( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  415. {
  416. }
  417. ///
  418. /// IEX_WriteCloseWnd
  419. __geta4 void IEX_WriteCloseWnd( __D0 UWORD ID, __A0 struct GenFiles *Files, __A1 struct IE_Data *IE )
  420. {
  421. }
  422. ///
  423.